// Copyright 2025 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef XLS_PASSES_CRITICAL_PATH_DELAY_ANALYSIS_H_
#define XLS_PASSES_CRITICAL_PATH_DELAY_ANALYSIS_H_

#include <cstdint>
#include <memory>
#include <vector>

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/types/span.h"
#include "xls/estimators/delay_model/delay_estimator.h"
#include "xls/ir/node.h"
#include "xls/passes/lazy_node_data.h"
#include "xls/passes/optimization_pass.h"

namespace xls {

class CriticalPathDelayAnalysis : public LazyNodeData<int64_t> {
 public:
  explicit CriticalPathDelayAnalysis(const DelayEstimator* delay_estimator);

  static absl::StatusOr<std::shared_ptr<CriticalPathDelayAnalysis>> Create(
      const AnalysisOptions& options);

  std::vector<Node*> NodesAtEndOfCriticalPath(FunctionBase* f) const;

 protected:
  int64_t ComputeInfo(
      Node* node,
      absl::Span<const int64_t* const> operand_infos) const override;

  absl::Status MergeWithGiven(int64_t& info,
                              const int64_t& given) const override;

 private:
  const DelayEstimator* delay_estimator_;
};

}  // namespace xls

#endif  // XLS_PASSES_CRITICAL_PATH_DELAY_ANALYSIS_H_
